package utils;

import android.util.Log;

import java.io.File;

import constants.Constants;

/**
 * Created by Administrator on 2018/11/7.
 */

public class UsbUtils {

    public static String getUsbPath(){
        StringBuilder sb = new StringBuilder();
        if (Constants.IS_FUYI) {
            sb.append("/mnt");
            File os = new File(sb.toString());
            if (os.exists()) {
                File[] files = os.listFiles();
                int count = 0;
                for (File file : files) {
                    if (file != null && file.getName().startsWith("usbhost")) {
                        File[] f = file.listFiles();
                        if (f != null && file.listFiles().length > 0) {
                            count++;
                            sb.append("/" + file.getName());
                            break;
                        }
                    }
                }
                if (count != 0) {
                    return sb.toString();
                } else {
                    return "";
                }
            }else {
                return "";
            }
        } else {
            sb.append("/mnt/usb_storage");
            File os = new File(sb.toString());
            if (os.exists()) {
                File[] files = os.listFiles();
                int count = 0;
                for (File file : files) {
                    File[] f = file.listFiles();
                    if (f.length > 0) {
                        count++;
                        sb.append("/" + file.getName());
                        File subFile = f[0];
                        sb.append("/" + subFile.getName());
                    }
                }
                if (count != 0) {
                    return sb.toString();
                } else {
                    return "";
                }
            }else {
                return "";
            }
        }
    }
}
